/* 
 * Copyright 2011 VelocitiSoftware
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package com.velociti.ikarus.ui.widget;

import java.util.Map;

import com.vaadin.terminal.PaintException;
import com.vaadin.terminal.PaintTarget;
import com.vaadin.ui.ClientWidget;
import com.vaadin.ui.Component;
import com.vaadin.ui.CustomComponent;
import com.velociti.ikarus.widget.client.ui.VIkarusSlidingPanel;

/**
 * ######IkarusSlidingPanel##### 
 * -A JQuery animated sliding panel that can be
 *  attached to the edges(left,right,bottom,top) of the main window. -Standard
 * -Vaadin components can be added to the Sliding panel.
 * -Needs JQuery js.
 * 
 * @author Alper Turkyilmaz - VelocitiSoftware - 2011
 * @version 1.0.2
 * 
 */
@ClientWidget(VIkarusSlidingPanel.class)
public class IkarusSlidingPanel extends CustomComponent {
	public static final int EDGE_LEFT = 0;
	public static final int EDGE_RIGHT = 1;
	public static final int EDGE_TOP = 2;
	public static final int EDGE_BOTTOM = 3;

	public static final int BEGINING = 10;
	public static final int MIDDLE = 20;
	public static final int END = 30;

	int edge = EDGE_LEFT;
	int edgeLocation = MIDDLE;

	int offset = 0;
	boolean animationEnabled = true;
	int headerLocation = MIDDLE;
	boolean open = false;
	int animDuration = 1000;

	public IkarusSlidingPanel() {

	}

	public void changeVariables(Object source, Map<String, Object> variables) {
		super.changeVariables(source, variables);

		if (variables.containsKey("contentheight")) {
			getCompositionRoot().setHeight((String) variables.get("contentheight"));
		}
		if (variables.containsKey("contentwidth")) {
			getCompositionRoot().setWidth((String) variables.get("contentwidth"));
		}
		getCompositionRoot().requestRepaint();
	}

	public void paintContent(PaintTarget target) throws PaintException {
		super.paintContent(target);
		target.addAttribute("headerlocation", headerLocation);
		target.addAttribute("animenabled", animationEnabled);
		target.addAttribute("edge", edge);
		target.addAttribute("offset", offset);
		target.addAttribute("location", edgeLocation);
		target.addAttribute("open", open);
		target.addAttribute("duration", animDuration);
	}

	public int getEdge() {
		return edge;
	}

	public void setEdge(int orientation) {
		this.edge = orientation;
	}

	public int getOffset() {
		return offset;
	}

	public void setOffset(int offset) {
		this.offset = offset;
	}

	public Component getContent() {
		return getCompositionRoot();
	}

	public void setContent(Component content) {
		setCompositionRoot(content);
		requestRepaint();
	}

	public boolean isAnimationEnabled() {
		return animationEnabled;
	}

	public void setAnimationEnabled(boolean animationEnabled) {
		this.animationEnabled = animationEnabled;
		requestRepaint();
	}

	public int getHeaderLocation() {
		return headerLocation;
	}

	public void setHeaderLocation(int headerAlignment) {
		this.headerLocation = headerAlignment;
		requestRepaint();
	}

	public int getEdgeLocation() {
		return edgeLocation;
	}

	public void setEdgeLocation(int edgeLocation) {
		this.edgeLocation = edgeLocation;
	}

	public boolean isOpen() {
		return open;
	}

	public void setOpen(boolean open) {
		this.open = open;
		requestRepaint();
	}

	public int getAnimDuration() {
		return animDuration;
	}

	public void setAnimDuration(int animDuration) {
		this.animDuration = animDuration;
		requestRepaint();
	}

}
